function register() {
    const username = document.getElementById('username').value;
    const password = document.getElementById('password').value;
    const confirmPassword = document.getElementById('confirm-password').value;

    if (username === '' || password === '' || confirmPassword === '') {
        alert('请填写完整信息');
        return;
    }

    // 验证密码是否一致
    if (password !== confirmPassword) {
        alert('两次输入的密码不一致');
        return;
    }

    // 创建表单数据对象
    const formData = new FormData();
    formData.append('username', username);
    formData.append('password', password);

    // 使用fetch提交表单
    fetch('../api/register.php', {
        method: 'POST',
        body: formData
    })
    .then(response => response.json())
    .then(data => {
        if (data.success) {
            alert('注册成功');
            // 注册成功后的操作，例如跳转到登录页面
            window.location.href = '/login.html?username=' + encodeURIComponent(data.username);
        } else {
            alert('注册失败：' + data.message);
        }
    })
    .catch(error => {
        console.error('Error:', error);
        alert('注册失败');
    });
}